<template>
    <div class="home" v-if="isLoad">
        <div class="title">
            基本信息
        </div>
        <div class="info-line">
            <div>客户名称</div>
            <div>{{userInfoSource.name}}</div>
        </div>
        <div class="info-line">
            <div>联系电话</div>
            <div>{{userInfoSource.mobile}}</div>
        </div>
        <div class="info-line" style="border: none;">
            <div>通讯地址</div>
            <div>{{userInfoSource.address}}</div>
        </div>
        <div class="linellae"></div>
        <div class="title">业务信息</div>
        <div class="info-line">
            <div>业务类型</div>
            <div>{{userInfoSource.business_text}}</div>
        </div>
        <div class="info-line">
            <div>所属业务</div>
            <div>{{userInfoSource.salesman_text}}</div>
        </div>
        <div class="info-line">
            <div>所属客服</div>
            <div>{{userInfoSource.customer_text}}</div>
        </div>
        <div class="info-line">
            <div>所属财务</div>
            <div>{{userInfoSource.finance_text}}</div>
        </div>
        <div class="info-line">
            <div>所属工伤</div>
            <div>{{userInfoSource.compensate_text}}</div>
        </div>
        <div v-for="(item,index) in goodsSource" :key="index">
            <div class="info-line border-last">
                <div>产品名称</div>
                <div>
                    <div>{{item.goods_name}}</div>
                    <div>{{item.price}}元</div>
                </div>
            </div>
        </div>

        <div style="height: 10vh;"></div>
        <footer-item :idx="0"></footer-item>
    </div>
</template>

<script>
    // @ is an alias to /src
    import footerItem from '@/components/footer.vue'
    import headerItem from '@/components/header.vue'
    import {getWXUserId} from '@/wxConfig/getWXUserId'

    export default {
        name: 'home',
        data() {
            return {
                isLoad: false,
                userInfoSource: {},
                goodsSource: {},
            };
        },
        components: {
            footerItem,
            headerItem
        },
        methods: {
            getNewsData() {
                let params = {};
                this.$post("/api/workwx/index", params)
                    .then(res => {
                        if (res.code == 1) {
                            // this.newsSource = res.data
                            getWXUserId(res.data.js_wx_config, res.data.js_agent_config, this.getUserSuccess)
                        }
                    })
                    .catch(err => {
                    });
            },
            getUserSuccess(id) {
                localStorage.setItem('wx_member_id', id);
                this.getUserToken();

            },
            getUserInfo() {
                let params = {
                    wx_member_id: localStorage.getItem('wx_member_id'),
                    token: localStorage.getItem('token'),
                };
                this.$post("/api/common/index", params)
                    .then(res => {
                        if (res.code == 1) {
                            this.$Toast.clear();
                            this.isLoad = true
                            this.userInfoSource = res.data.info
                            this.goodsSource = res.data.goods_list
                        }
                        if (res.code == 40001) {
                            this.$Toast.clear();
                            this.$router.replace('limited')
                        }
                    })
                    .catch(err => {
                    });
            },
            getUserToken() {
                let params = {
                    wx_member_id: localStorage.getItem('wx_member_id'),
                    token: localStorage.getItem('token'),
                };
                this.$post("/api/common/get_auth_menu", params)
                    .then(res => {
                        if (res.code == 1) {
                            localStorage.setItem('token', res.data.wx_user_id)
                            console.log(res.data.auth_menu_list.toString(','));
                            localStorage.setItem('menuList', res.data.auth_menu_list.toString(','))
                            this.getUserInfo();
                        } else if (res.code == 0) {
                            this.$router.push('/notData')
                        }
                    })
                    .catch(err => {
                    });
            }
        },
        created() {
            this.$Toast.loading({
                duration: 4000, // 持续展示 toast
                message: '授权中...',
                forbidClick: true
            });

            this.getNewsData();
            if (process.env.NODE_ENV == "development") {
                this.getUserInfo();
            }
        },

    }
</script>
<style scoped lang="less">
    .info-line {
        border-bottom: 1px solid #eee;
        margin: 0 16px;
        padding: 12px 0;
        display: flex;
        align-items: center;
        justify-content: space-between;

        > div:nth-of-type(1) {
            width: 96px;
            color: #777777;
            font-size: 14px;
        }

        > div:nth-of-type(2) {
            flex: 1;
            font-size: 15px;
            color: #333;
        }
    }

    .border-last:last-child {
        border: none;
    }
</style>
